import threading
import Queue
import time, random

(ADD_USER, EXIT) = range(2)

class Worker(threading.Thread):

    def __init__(self, queue, worker_number):
        self.__queue = queue
        self.worker_number = worker_number
        threading.Thread.__init__(self)

    def run(self):
        while 1:
            (action, params) = self.__queue.get()
            if action == EXIT:
                break
            elif action == ADD_USER:
                print 'worker #%d:Anadiendo usuario %s'%(self.worker_number, params)
            elif action == 'add_websocket':
                pass
            time.sleep(random.randint(10,100)/100.0)
            print  "finished"
    
    def add_user(self, user):
        self.__queue.put((ADD_USER, user))

  

        